package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;

public class ProjectSateDialogFragment extends DialogFragment {
  protected static final String EXTRA_VALUE =
      "com.isunland.managesystem.ui.ProjectSateDialogFragment.extra_value";
  private int[] choiceIds = new int[] {
      R.string.already_over, R.string.no_over, R.string.all
  };
  private String[] choiceStrings = new String[choiceIds.length];
  private String overState = "";//状态
  private String overStateName = "";

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new OnClickListener() {

          @Override public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case 0:
                overState = "T";
                overStateName = "已滞后";

                break;
              case 1:
                overState = "F";
                overStateName = "未滞后";
                break;
              case 2:
                overState = "";
                overStateName = "全部";
                break;

              default:
                break;
            }
            CustomerDialog content = new CustomerDialog(overStateName, overState);

            Intent i = new Intent();
            i.putExtra(EXTRA_VALUE, content);
            if (getTargetFragment() == null) {
              return;
            }
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
